package me.firstapp.manage.order;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import me.firstapp.common.json.SingleObject;
import me.firstapp.common.module.shop.JsonOrder;
import me.firstapp.manage.common.BaseManage;
import me.firstapp.spi.shop.OrderService;

@Controller
@RequestMapping(value = "/orderManage")
public class OrderManagePage extends BaseManage {

	@Autowired
	private OrderService orderService;

	@RequestMapping(value = "/orderList.html", method = RequestMethod.GET)
	public ModelAndView orderListView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return new ModelAndView("order/orderList", modelMap);
	}

	@RequestMapping(value = "/orderItemList.html", method = RequestMethod.GET)
	public ModelAndView orderItemListView(Long orderId, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		modelMap.put("orderId", orderId);
		return new ModelAndView("order/orderItemList", modelMap);
	}

	@RequestMapping(value = "/payRecordList.html", method = RequestMethod.GET)
	public ModelAndView payRecordListView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return new ModelAndView("order/payRecordList", modelMap);
	}

	@RequestMapping(value = "/orderAddress.html", method = RequestMethod.GET)
	public ModelAndView orderAddressView(String orderNo, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		SingleObject<JsonOrder> result = orderService.findOrderByOrderNo(orderNo, false);
		modelMap.put("address", result.getObject().getReceiveAddress());
		return new ModelAndView("order/orderAddress", modelMap);
	}

	@RequestMapping(value = "/distributeOrder.html", method = RequestMethod.GET)
	public ModelAndView distributeOrderView(String orderNo, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		modelMap.put("orderNo", orderNo);
		return new ModelAndView("order/distributeOrder", modelMap);
	}

	@RequestMapping(value = "/distributeCallList.html", method = RequestMethod.GET)
	public ModelAndView distributeCallListView(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		return new ModelAndView("order/distributeCallList", modelMap);
	}
}
